import request from '@/utils/request'

export default {
    getRoleList(searchModel) {
        return request({
            url: '/roles',
            method: 'get',
            params: {
                page: searchModel.pageNo,
                paginate: searchModel.pageSize,
                pageSize: searchModel.pageSize,
                name: searchModel.name,
                guard_name: searchModel.guard_name,
            }
        });
    },
    getAllRoles() {
        return request({
            url: '/allRoles',
            method: 'get',
            params: {}
        });
    },
    addRole(roleForm) {
        return request({
            url: '/roles',
            method: 'post',
            params: {
                name: roleForm.name,
            }
        });
    },
    deleteRole(id) {
        return request({
            url: '/roles/delete/' + id,
            method: 'post',
            params: {
            }
        });
    },
    getRoleById(id){
        return request({
            url:'/roles/'+id,
            method: 'get',
            params: {
            }
        })
    },
    updateRole(role){
        return request({
            url:'/roles/'+role.id,
            method: 'post',
            params: {
                name:role.name,
            }
        })
    },
    saveRole(role){
        if(role.id == null || role.id == undefined){
            return this.addRole(role);
        }
        return this.updateRole(role);
    },
    getPermissionsByRoleId(id){
        return request({
            url: '/roles/getPermission/' + id,
            method: 'get',
        });
    },
    savePermissions(id,questionForm){
        // console.log();
        return request({
            url: '/roles/savePermissions/' + id,
            method: 'post',
            params: {
                permissionList:questionForm.description,
            }
        });
    }
}